n, m = map(int, input().split())
grid = set()
for _ in range(m):
    u, v, w = map(int, input().split())
    grid.add((u, v, w))

minist = [float('inf')] * (n + 1)
minist[1] = 0
# 对所有边进行一个松弛操作
# 进行n-1 次
for k in range(n - 1):
    for u, v, w in grid:
        minist[v] = min(minist[v], minist[u] + w)

if minist[n] != float('inf'):
    print(minist[n])
else:
    print("unconnected")
